﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.BLL;
using Com.CMS263.PO;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage.ProductManage
{
    public partial class product_action : System.Web.UI.Page
    {
        ProductBLL pbll = new ProductBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            string op = Request["op"];
            if (op.ToLower() == "del")
            {
                int id = Convert.ToInt32(Request["id"]);
                if (pbll.Delete("Product", id))
                {
                    Response.Write("1");
                }
                else
                {
                    Response.Write("fail");
                }
                
            }
            if (op.ToLower() == "delprdouctimage")
            {
                
                ProductImagesBLL pibll = new ProductImagesBLL();
                int id = Convert.ToInt32(Request["id"]);
                if (pibll.Delete("ProductImage", id))
                {
                    Response.Write("1");
                }
                else
                {
                    Response.Write("fail");
                }
                
            }
            if (op.ToLower() == "updateitem")
            {
                int id = Convert.ToInt32(Request["id"]);
                Product prod = new Product();
                prod = (Product)pbll.FindModelById("Product", id);
                if (prod.IsPub)
                {
                    prod.IsPub = false;
                }
                else
                {
                    prod.IsPub = true;
                }
                pbll.entity = prod;
                if (pbll.UpDate())
                {
                    Response.Write(Convert.ToInt32(prod.IsPub).ToString());
                }
                else
                {
                    Response.Write("fail");
                }
            }
            
        }
    }
}
